/*
 * FloorTile.java
 *
 * Created on 22. Dezember 2006, 20:50
 *
 * Copyright (c) 2007 Daniel Gronau
 *
 * This file is part of KanjiTori.
 *
 * KanjiTori is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * KanjiTori is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

package kanjitori.map.tile;

import com.jme.scene.TriMesh;
import java.util.HashMap;
import java.util.Map;
import kanjitori.graphics.FloorQuad;

/**
 *
 * @author Pirx
 */
public class FloorTile extends AbstractTile {
    
    private static final String RENDERSTATE = "renderstate";
    private static final String FLIPPED = "flipped";
    
    private String renderstate;
    boolean flipped = false;  //for ceilings use flipped = true
    private FloorQuad floor;
    
    /** Creates a new instance of FloorTile 
     * @param name 
     * @param ref 
     * @param renderstate 
     */
    public FloorTile(String name, char ref, String renderstate) {
        super(name, ref);
        this.renderstate = renderstate;
    }

    public FloorTile(String name, char ref, String renderstate, boolean flipped) {
        super(name, ref);
        this.renderstate = renderstate;
        this.flipped = flipped;
    }
    
    public FloorTile() {
    }
            
    public void init() {    
        floor = new FloorQuad("floor", 2, 2, flipped ? FloorQuad.DOWN : FloorQuad.UP);
    }

    public void setParams(Map<String, String> map) {
        renderstate = map.get(RENDERSTATE);
        String fl = map.get(FLIPPED); 
        if (fl != null) {
           flipped = Boolean.parseBoolean(fl); 
        }
    }

    public Map<String, String> getParams() {
        Map<String, String> map = new HashMap<String, String>();
        map.put(RENDERSTATE, renderstate);
        map.put(FLIPPED, "" + flipped);
        return map;
    }

    public TriMesh getMesh(int index) {
        if (floor == null) {
            init();
        }
        return floor;
    }

    public int getSize() {
        return 1;
    }

    public String getRenderStateName(int index) {
        return renderstate;
    }
    
}
